package com.example.rumen;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class RadioBtn extends AppCompatActivity {

    private RadioGroup radio_group;
    private Button btn_xpQD;
    private RadioButton rad_btn1;
    private RadioButton rad_btn2;
    private RadioButton rad_btn3;
    private RadioButton rad_btn4;
    private RadioButton rad_btn5;
    private String filme;

    @Override
    @SuppressLint("MissingInflatedId")
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_radio_btn);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


        int images[] = new int[]{R.drawable.changjh, R.drawable.hana, R.drawable.ershi, R.drawable.fengshen, R.drawable.gongfu};
        ImageView image_view = findViewById(R.id.imageView_318);
        radio_group = findViewById(R.id.radiogroup);

        radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                filme = "";
                if (checkedId == R.id.radioButton1) {
//                    image_view.setImageResource(R.drawable.changjh);
                    //获取text
                    rad_btn1 = findViewById(R.id.radioButton1);
                    filme = rad_btn1.getText().toString();
                    image_view.setImageResource(images[0]);

                } else if (checkedId == R.id.radioButton2) {
                    rad_btn2 = findViewById(R.id.radioButton2);
                    filme = rad_btn2.getText().toString();
                    image_view.setImageResource(R.drawable.nezha2);
                } else if (checkedId == R.id.radioButton3) {
                    rad_btn3 = findViewById(R.id.radioButton3);
                    filme = rad_btn3.getText().toString();
                    image_view.setImageResource(R.drawable.ershi);
                } else if (checkedId == R.id.radioButton4) {
                    rad_btn4 = findViewById(R.id.radioButton4);
                    filme = rad_btn4.getText().toString();
                    image_view.setImageResource(R.drawable.fengshen);
                } else if (checkedId == R.id.radioButton5) {
                    rad_btn5 = findViewById(R.id.radioButton5);
                    filme = rad_btn5.getText().toString();
                    image_view.setImageResource(R.drawable.gongfu);
                }
            }
        });
        //数据传输
        btn_xpQD = findViewById(R.id.button_318_xpQD);
        btn_xpQD.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), Select_seat.class);
                intent.putExtra("filme", filme);
                startActivity(intent);
                finish();
            }
        });

    }
}